#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
    Part of Seagull - The Pyhon Pages engine
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    magic.py:
      Mapping from filenames to mime-types
"""
__author__ = 'Jonathan Slenders <jonathan at slenders dot be>'
__license__ = 'GNU LGPL'


import os

_magic = {
	'.css': 'text/css',
	'.gif': 'image/gif',
	'.jpeg': 'image/jpeg',
	'.jpg': 'image/jpeg',
	'.html': 'text/html',
	'.js': 'text/javascript',
	'.pdf': 'application/pdf',
	'.png': 'image/png',
	'.txt': 'text/plain',
	'.xaml': 'application/xaml+xml',
	'.xhtml': 'application/xhtml+xml',
	'.xap': 'application/x-silverlight-app',
	'.xml': 'text/xml',
	}


# TODO: rename function to: mime_type_from_filename
def content_type_from_filename(filename):
	global _magic

	(base, ext) = os.path.splitext(filename)

	if _magic.has_key(ext):
		return _magic[ext]
	else:
		return 'application/force-download'
